<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of crud
 *
 * @author farid
 */
class Model extends CI_Model {

    public $columns;
    public $table;
    public $primary_keys;
    public $foreign_keys;

    function __construct($table = null) {
        //parent::Model();

        if ($table)
            $this->table = $table;

        // load library adodbx
        $this->load->library('ci_adodb');
        //$this->init();
    }

    public static function load($table) {
        $this->load->library('ci_adodb');
        $this->init();
    }

    function init() {
        $CI = & get_instance();
        $this->columns = $CI->adodb->MetaColumns($this->table);
        $this->primary_keys = $CI->adodb->MetaPrimaryKeys($this->table);
        $this->foreign_keys = $CI->adodb->MetaForeignKeys($this->table);

        $pk = $CI->adodb->MetaPrimaryKeys($this->table);

        if (count($pk) > 0)
            foreach ($pk as $k => $v) {
                $this->columns->$v->is_primary = true;
            }

        echo "<pre>";
        print_r($this->columns);
        print_r($this->primary_keys);

        print_r($this->foreign_keys);
        die('ee');
    }

}

?>
